<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
| 当前目录的路由 需要路由前缀 /api/
*/

Route::get('error_403', function(){
   return error("用户已失效, 请重新登录", [], 403);
})->name("error_403");

Route::post('login','LoginController@login')->middleware('throttle:10,1');
Route::post('logout','LoginController@logout');

Route::group(['middleware' => ['auth:api']], function () {
    Route::any('/user', function (Request $request) {
        //dd($request->user()->token()->id);
        return success('用户信息', $request->user());
    });

    Route::group(['namespace' => 'System', 'prefix' => 'system'], function(){
        //获取路由菜单
        Route::get('menuRoutes', 'MenuController@routes');
        //获取菜单树
        Route::get('menuTree', 'MenuController@tree');
        //保存树节点信息
        Route::post('saveMenuNode', 'MenuController@saveNode');
        //新增树节点
        Route::post('addMenuNode', 'MenuController@addMenuNode');
        //删除树节点
        Route::post('delMenuNode', 'MenuController@delMenuNode');

        //获取用户列表
        Route::post('userList', 'UserController@list');
        //更新用户信息
        Route::post('userSet', 'UserController@set');

        //获取角色列表
        Route::post('roleList', 'RoleController@list');
        //搜索角色
        Route::post('roleSearch', 'RoleController@search');
        //新增角色
        Route::post('roleSave', 'RoleController@save');
        //角色权限
        Route::post('rolePermission', 'RoleController@permission');
        //修改权限
        Route::post('rolePermissionSave', 'RoleController@permissionSave');
    });
});

Route::group(['namespace' => 'Debug', 'prefix' => 'debug'], function(){
    Route::get('tokens', 'DebugController@tokens');
});


